﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _MetalSlug.Soldiers.Units;
using Microsoft.Xna.Framework;
using _MetalSlug.Soldiers.Factory;
using _MetalSlug.MyCharacters.Characters;
using _MetalSlug.Mementoes;

namespace _MetalSlug.Mission
{
    public class MissionFactory
    {
        protected int CurrentID;
        protected Random random = new Random();

        public virtual void IntialAttribute()
        {
            CurrentID = 0;
        }

        protected virtual List<Enemy> CreateMiniGunSoldier(int Count)
        {
            
            List<Enemy> lstNewEnemy = new List<Enemy>();
            for (int i = 0; i < Count; i++)
            {
                Vector2 TopLeftOfEnemy = new Vector2(random.Next(800, 5000), 260);
                CurrentID++;
                Enemy temp =
                    (MiniGunSoldier)
                    SoldierStore.GetInstance().Produce(CurrentID,
                                                       Enemy.TYPE_SOLDIER.MINIGUN_SOLDIER,
                                                       TopLeftOfEnemy);
                lstNewEnemy.Add(temp);
            }

            return lstNewEnemy;
        }

        protected virtual List<Enemy> CreateBazokaSoldier(int Count)
        {
            List<Enemy> lstNewEnemy = new List<Enemy>();
            for (int i = 0; i < Count; i++)
            {
                Vector2 TopLeftOfEnemy = new Vector2(random.Next(800, 5000), 260);
                CurrentID++;
                Enemy temp =
                    (BazokaSoldier)
                    SoldierStore.GetInstance().Produce(CurrentID,
                                                       Enemy.TYPE_SOLDIER.BAZOKA_SOLDIER,
                                                       TopLeftOfEnemy);
                lstNewEnemy.Add(temp);
            }

            return lstNewEnemy;
        }

        protected virtual List<Enemy> CreateAkSoldier(int Count)
        {
            List<Enemy> lstNewEnemy = new List<Enemy>();
            for (int i = 0; i < Count; i++)
            {
                Vector2 TopLeftOfEnemy = new Vector2(random.Next(1000, 4000), 260);
                CurrentID++;
                Enemy temp = (AKSoldier)SoldierStore.GetInstance().Produce(CurrentID,
                                                                           Enemy.TYPE_SOLDIER.AK_SOLDIER,
                                                                           TopLeftOfEnemy);
                lstNewEnemy.Add(temp);
            }

            return lstNewEnemy;
        }

        protected virtual List<Enemy> CreateHelicoper(int Count)
        {
            List<Enemy> lstNewEnemy = new List<Enemy>();
            for (int i = 0; i < Count; i++)
            {
                Vector2 TopLeftOfEnemy = new Vector2(random.Next(500, 5000), random.Next(30, 50));
                CurrentID++;
                Enemy temp = (Helicoper)SoldierStore.GetInstance().Produce(CurrentID,
                                                                           Enemy.TYPE_SOLDIER.HELICOPER,
                                                                           TopLeftOfEnemy);
                lstNewEnemy.Add(temp);
            }

            return lstNewEnemy;
        }

        protected virtual List<Enemy> CreateTycoon(int Count)
        {
            List<Enemy> lstNewEnemy = new List<Enemy>();
            for (int i = 0; i < Count; i++)
            {
                Vector2 TopLeftOfEnemy = new Vector2(5300, 0);
                CurrentID++;
                Enemy temp = (Tycoon)SoldierStore.GetInstance().Produce(CurrentID,
                                                                        Enemy.TYPE_SOLDIER.TYCOON,
                                                                        TopLeftOfEnemy);
                lstNewEnemy.Add(temp);
            }

            return lstNewEnemy;
        }

        

        public virtual void InitialAttributeCharacter(MyCharacter Character)
        {

        }

        protected MyCharacter BuildCharacter(String NameOfHero)
        {
            MyCharacter NewCharacter = null;
            switch(NameOfHero)
            {
                case "Marco":
                    NewCharacter = new Marco(999, new Vector2(150, 290), Vector2.Zero);
                    break;
            }

            if(NewCharacter == null)
            {
                NewCharacter = new Marco(999, new Vector2(150, 290), Vector2.Zero);
            }

            return NewCharacter;
        }

        public virtual MyCharacter CreateCharacter(String NameOfHero)
        {
            MyCharacter newCharacter = BuildCharacter(NameOfHero);
            InitialAttributeCharacter(newCharacter);
            return newCharacter;
        }


        public virtual void InitialAttributeForEnemy(List<Enemy> lstNewEnemy)
        {

        }

        protected virtual List<Enemy> CreateEnemyWithTypeAndNumber(Enemy.TYPE_SOLDIER Type, int Count)
        {
            List<Enemy> lstNewEnemy = new List<Enemy>();
            switch (Type)
            {
                case Enemy.TYPE_SOLDIER.MINIGUN_SOLDIER:
                    lstNewEnemy = CreateMiniGunSoldier(Count);
                    break;

                case Enemy.TYPE_SOLDIER.BAZOKA_SOLDIER:
                    lstNewEnemy = CreateBazokaSoldier(Count);
                    break;

                case Enemy.TYPE_SOLDIER.AK_SOLDIER:
                    lstNewEnemy = CreateAkSoldier(Count);
                    break;

                case Enemy.TYPE_SOLDIER.HELICOPER:
                    lstNewEnemy = CreateHelicoper(Count);
                    break;

                case Enemy.TYPE_SOLDIER.TYCOON:
                    lstNewEnemy = CreateTycoon(Count);
                    break;
            }

            return lstNewEnemy;
        }

        public virtual List<Enemy> CreateEnemy(Enemy.TYPE_SOLDIER Type, int Count)
        {
            List<Enemy> lstNewEnemy = CreateEnemyWithTypeAndNumber(Type,Count);
            InitialAttributeForEnemy(lstNewEnemy);
            return lstNewEnemy;
        }

        protected MyMap BuildMap(int Level, Vector2 Size)
        {
            MyMap newMap = new MyMap(String.Format("Map/Map{0}", Level), Size);
            return newMap;
        }

        public virtual void InitialAttributeMap(MyMap Map)
        {
        }

        public virtual MyMap CreateMap(int Level, Vector2 Size)
        {
            MyMap newMap = BuildMap(Level,Size);
            InitialAttributeMap(newMap);
            return newMap;
        }
    }
}
